package com.rh.number.common;

public class Result<T> {
    private int code;    // 业务状态码
    private String msg;  // 消息描述
    private T data;      // 响应数据

    public Result() {

    }


    // 必须提供Getter方法
    public int getCode() { return code; }
    public String getMsg() { return msg; }
    public T getData() { return data; }

    public Result(int i, String msg, T data) {
    }

    // 成功构造器（含数据）
    public static Result<Void> success() {
        Result<Void> result = new Result<>();
        result.code = 200;
        result.msg = "success";
        result.data = null; // 明确null值
        return result;
    }

    // 失败构造器（含状态码+消息）
    public static <T> Result<T> fail(int code, String msg) {
        return new Result<>(code, msg, null);
    }

    public void setCode(int code) {
        this.code = code;
    }
    public void setMsg(String msg) {
        this.msg = msg;
    }
    public void setData(T data) {
        this.data = data;
    }
    public static <T> Result<T> success(T data) {
        Result<T> result = new Result<>();
        result.setCode(200);    // 确保设置为成功状态码
        result.setMsg("success");
        result.setData(data);
        return result;
    }

    // 错误响应
    public static <T> Result<T> error(int code, String msg) {
        Result<T> result = new Result<>();
        result.setCode(code);
        result.setMsg(msg);
        return result;
    }
}
